<?php

class RequestForm extends BaseRequestForm {

    public function configure() {
        parent::configure();

        $requestTypes = RequestTypeRestResource::singleton()->findAllAndMap('id', 'description');

        $this->widgetSchema['status'] = new sfWidgetFormInputHidden();

        switch ($this->getOption('mode')) {
            case 'new':
            case 'edit';
                $i18nDatePickerWidget = new sfWidgetFormJQueryDate(array(
                    'image'=>'/images/calendar.png',
                    'culture' => sfContext::getInstance()->getUser()->getCulture(),
                    'date_widget' => new sfWidgetFormI18nDate(array('culture' => sfContext::getInstance()->getUser()->getCulture()))));

                $this->widgetSchema['from'] = $i18nDatePickerWidget;
                $this->widgetSchema['to'] = $i18nDatePickerWidget;
                $this->widgetSchema['askComment']->setLabel('Comment');
                $this->widgetSchema['answerComment'] = new sfWidgetFormInputHidden();
                $this->widgetSchema['typeId'] = new sfWidgetFormChoice(array('choices' => $requestTypes, 'label' => 'Type'));
                break;
            case 'validate':
                $this->widgetSchema['from'] = new sfWidgetFormInputHidden(array('label' => 'From'));
                $this->widgetSchema['to'] = new sfWidgetFormInputHidden(array('label' => 'To'));
                $this->widgetSchema['askComment']->setLabel('Comment from user');
                $this->widgetSchema['answerComment']->setLabel('Your comment');
                $this->widgetSchema['typeId'] = new sfWidgetFormInputHidden(array('label' => 'Type'));
                $this->type = $requestTypes[$this->getObject()->typeId];
                break;
        }
    }

}
